package converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;

/**
 * 
 * <p>Title: CustomDateConverter</p>
 * <p>Description: 自定义日期转换器</p>
 */
public class CustomDateConverter implements Converter<String, Date> {
	@Override
	public Date convert(String source) {
		if(source==null || source.isEmpty()){
			return null;
		}
			//进行日期转换
			try {
				return new SimpleDateFormat("yyyy-MM-dd").parse(source);
			} catch (ParseException e) {
				try {
					return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(source);
				} catch (ParseException e1) {
					e1.printStackTrace();
				}
				e.printStackTrace();
			}
			
		
		return null;
	}

}
